package top.zywork.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import top.zywork.common.BeanUtils;
import top.zywork.dto.PagerDTO;
import top.zywork.query.SchoolOrderAddressUserQuery;
import top.zywork.security.SecurityUtils;
import top.zywork.service.SchoolOrderAddressUserService;
import top.zywork.vo.ResponseStatusVO;
import top.zywork.vo.PagerVO;
import top.zywork.vo.SchoolOrderAddressUserVO;

/**
 * SchoolOrderAddressUserController控制器类<br/>
 *
 * 创建于2020-10-30<br/>
 *
 * @author http://zywork.top 王振宇
 * @version 1.0
 */
@RestController
@RequestMapping("/school-order-address-user")
@Slf4j
public class SchoolOrderAddressUserController extends BaseController {

    private SchoolOrderAddressUserService schoolOrderAddressUserService;

    @GetMapping("admin/multi/{id}")
    public ResponseStatusVO listById(@PathVariable("id") Long id) {
        PagerDTO pagerDTO = schoolOrderAddressUserService.listById(id);
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), SchoolOrderAddressUserVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    @GetMapping("admin/all")
    public ResponseStatusVO listAll() {
        PagerDTO pagerDTO = schoolOrderAddressUserService.listAll();
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), SchoolOrderAddressUserVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    @PostMapping("admin/all-cond")
    public ResponseStatusVO listAllByCondition(@RequestBody SchoolOrderAddressUserQuery schoolOrderAddressUserQuery) {
        PagerDTO pagerDTO = schoolOrderAddressUserService.listAllByCondition(schoolOrderAddressUserQuery);
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), SchoolOrderAddressUserVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    @PostMapping("admin/pager-cond")
    public ResponseStatusVO listPageByCondition(@RequestBody SchoolOrderAddressUserQuery schoolOrderAddressUserQuery) {
        PagerDTO pagerDTO = schoolOrderAddressUserService.listPageByCondition(schoolOrderAddressUserQuery);
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), SchoolOrderAddressUserVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    /**
     * @Author: 95DBC
     * @Date: 2020/10/30 13:46
     * @param schoolOrderAddressUserQuery
     * @Description: 只查询骑手接了的需求
     *
     */
    @PostMapping("user/pager-cond-courier")
    public ResponseStatusVO listPageByUser(@RequestBody SchoolOrderAddressUserQuery schoolOrderAddressUserQuery) {
        schoolOrderAddressUserQuery.setSchoolOrderOrderUserId(SecurityUtils.getJwtUser().getUserId());
        schoolOrderAddressUserQuery.setSchoolOrderIsActive(new Byte("0"));
        return listPageByCondition(schoolOrderAddressUserQuery);
    }
    /**
     * @Author: 95DBC
     * @Date: 2020/10/30 13:46
     * @param schoolOrderAddressUserQuery
     * @Description: 只查询用户自己的订单
     *
     */
    @PostMapping("user/pager-cond-user")
    public ResponseStatusVO listPageBy(@RequestBody SchoolOrderAddressUserQuery schoolOrderAddressUserQuery) {
        schoolOrderAddressUserQuery.setSchoolOrderUserId(SecurityUtils.getJwtUser().getUserId());
        schoolOrderAddressUserQuery.setSchoolOrderIsActive(new Byte("0"));
        return listPageByCondition(schoolOrderAddressUserQuery);
    }

    @Autowired
    public void setSchoolOrderAddressUserService(SchoolOrderAddressUserService schoolOrderAddressUserService) {
        this.schoolOrderAddressUserService = schoolOrderAddressUserService;
    }
}